feat(parser): richer, actionable error messages on bad spec input - #137
Merged
Conversation
…rrors Thread an RFC 6901 JSON pointer through schema hydration so the depth-bound (#107 sibling) and node-count guards name WHERE in the document the offending node sits, e.g. 'at #/components/schemas/Deep/properties/next/...'. The pointer is escaped (~ -> ~0, / -> ~1) and degrades to no-location cleanly when the reader cannot pinpoint the node. The structural rejections (missing or mistyped openapi version, missing or mistyped info) now state the pointer, the expected-vs-found shape (a string, a number, an object, missing), and an actionable hint. The depth-bound and node-count messages also name the source file and point at --max-depth / max_depth. The pointer only ever appears in exception text, never in generated output.
…errors The decode-failure wrapper now names whether the file was parsed as JSON or YAML (taken from the extension, falling back to the first-byte sniff) and adds a hint about that detection, so a YAML file with a .json extension no longer produces an opaque 'Failed to parse' message. The size-guard message names the offending file and points at both the --max-bytes flag and the max_bytes config key. Output text only; no generated output changes.
Contributor
Qodana for PHPIt seems all right 👌 No new problems were found according to the checks applied 💡 Qodana analysis was run in the pull request mode: only the changed files were checked Detected 12 dependenciesThird-party software listThis page lists the third-party software dependencies used in project
Contact Qodana teamContact us at qodana-support@jetbrains.com
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Richer, more actionable error messages when the generator is handed bad INPUT (a malformed spec). Closes the "Richer error messages on bad input" ROADMAP follow-up. This touches only the generator's own error text and the context plumbing behind it; it does NOT change any generated output (confirmed: only parser source + parser tests changed, all output gates byte-identical).
Scope
The config loader (
StandaloneConfigLoader) and CLI (StandaloneApplication,OptionValidator) messages were already excellent (they name the offending key/option, allowed values, and hints), so they were left untouched. The parser was the weakest surface and the focus here.Before / after (parser messages enriched)
openapi: now names the found type and theswaggerkey hint, pointing at#/openapi.... at #/openapi.info: nowthe required '#/info' object is missing. Add an 'info' object with at least a 'title' and a 'version'.#/components/schemas/.../...pointer where the bound tripped, plus how to raise it.How
A
$pointerparameter (RFC 6901,~//escaped) is threaded fromread()through component schemas and every subschema position (properties, items, additionalProperties, allOf/oneOf/anyOf/not, prefixItems). It degrades to an empty pointer (noat ...suffix) for positions the reader does not pinpoint, so a message never shows a misleading partial pointer. Exit codes and exception types are unchanged (ParseException, config/spec errors still exit 2).Tests
Extended
OpenApiReaderTestandSpecParserTestto assert the new context (pointer, escaped pointer, expected-vs-found type, hints, source filename, attempted format) so the messages cannot silently regress.Gates (local, all green)
composer test 2185 passed / 5 skipped, test:type 100%, stan clean, Pint clean, deptrac 0. No generated-output gate (corpus baseline, ServerScaffold snapshot, drift, conformance golden) changed.